# Maintainer: AlexWMF <alexxwmf@gmail.com>

_realname=leechcraft

pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
#provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
#conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")

pkgver=0.6.70_1886_gba1d0d9
pkgrel=1
pkgdesc="LeechCraft is a free open source cross-platform modular live environment."
arch=('any')
license=('Boost')
url="https://leechcraft.org/"
depends=("${MINGW_PACKAGE_PREFIX}-boost"
        "${MINGW_PACKAGE_PREFIX}-djvulibre"
        "${MINGW_PACKAGE_PREFIX}-ffmpeg"
        "${MINGW_PACKAGE_PREFIX}-glib2"
        "${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
        "${MINGW_PACKAGE_PREFIX}-gst-plugins-good"
        "${MINGW_PACKAGE_PREFIX}-gst-plugins-ugly"
        "${MINGW_PACKAGE_PREFIX}-gstreamer"
        "${MINGW_PACKAGE_PREFIX}-hunspell"
        "${MINGW_PACKAGE_PREFIX}-libguess"
        "${MINGW_PACKAGE_PREFIX}-liblastfm-qt4"
        "${MINGW_PACKAGE_PREFIX}-libtorrent-rasterbar"
        "${MINGW_PACKAGE_PREFIX}-libxml2"
        "${MINGW_PACKAGE_PREFIX}-openssl"
        "${MINGW_PACKAGE_PREFIX}-pcre"
        "${MINGW_PACKAGE_PREFIX}-poppler-qt4"
        "${MINGW_PACKAGE_PREFIX}-qca-qt4-git"
        "${MINGW_PACKAGE_PREFIX}-qjson-qt4"
  #      "${MINGW_PACKAGE_PREFIX}-qt-mobility-qt4"
        "${MINGW_PACKAGE_PREFIX}-qwt-qt4"
        "${MINGW_PACKAGE_PREFIX}-qxmpp-qt4"
        "${MINGW_PACKAGE_PREFIX}-speex"
        "${MINGW_PACKAGE_PREFIX}-taglib"
        "${MINGW_PACKAGE_PREFIX}-tidyhtml")

makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
            "${MINGW_PACKAGE_PREFIX}-gcc"
            "${MINGW_PACKAGE_PREFIX}-pkg-config")

options=(!strip !buildflags)

#source=(${_realname}.tar.gz::"https://github.com/0xd34df00d/${_realname}/archive/${pkgver}.tar.gz"
source=("${_realname}"::"git+https://github.com/0xd34df00d/leechcraft.git"
        win_rc.patch
        xtazy_cmake.patch
        lmp_gst_paths.patch
        find_otr.patch
        find_poppler_cmake.patch
        find_azoth_multimediakit_cmake.patch
        azoth_xoox_multimediakit.patch
        htthare_cmake.patch
        azoth_find_qca2.patch
        find_gstreamer_cmake.patch
        find_qwt_cmake_common.patch
        find_rbtorrent_cmake.patch
        find_lmp_libguess_cmake.patch
        find_lhtr_libtidy_cmake.patch
        find_qjson_cmake_common.patch)
sha256sums=('SKIP'
            '6c329cc7adeee91d2b8e21323f84766230fe7edc61acecd8a5a104af41ed7cb7'
            '32051084fa60ef7eef744811cfe4e975af5b21eaac258a982c9cbcb77f5ca45c'
            '39ea740610ec4856740abc85d5f714cb4748ec71c0f621b03f81b7cb6570197b'
            '76e74c4028811e3fd38fe9faa3734c44dc92ef43490e8a9490fb0fbe953be382'
            'b6e37e7576da9caa1635c686cccadd1fcd3197f78112bc78b6630a1c6cb38b50'
            'a68699bf221146a30f2045f1ecaa3cad27dd2a00745f32cd7507275fcb9bf7f2'
            '13c951801d4c148386f767f84636b0b9ea0581a5a4c4e6bed5b916d18e498095'
            '28558ca0bc3f96ac2ad9f3262162f0640165284b6d1f46fb3ddc6c435b0d98f1'
            'dadfcde03da4696af702ce4535938183f819d3ff394c7e43065aae5cc5841ac2'
            'cbc7c908b651746c512eff8d12336f3b18b84c9d62916f65fbc248eab5da860c'
            '102ef354cde9f92c07c86503245edabbe57617df3db1d16d5aa6abc9cc75add6'
            'c42836ea10f175724618279036f405e5340026c38840025778d519127a2bf102'
            'eabe34538523f9a4979e2cd8f5444648850b100c166390218fc9a9a37b752756'
            '646cbe11a09e3c9c30f49cb686803c2a25415dde9c5294e39c71c47ea013e290'
            '44311e137efb44b472f8872b13d4c2c4c2c7b88d35f1c4ee3cae47d7ca8e4c62')

pkgver() {
  cd "$srcdir/$_realname"
  printf "%s" "$(git describe | sed 's/-/_/g')"
}

prepare() {
  cd "${srcdir}/${_realname}"
  patch -p0 -i ${srcdir}/win_rc.patch
  patch -p0 -i ${srcdir}/xtazy_cmake.patch
  patch -p0 -i ${srcdir}/lmp_gst_paths.patch
  patch -p0 -i ${srcdir}/find_otr.patch
  patch -p0 -i ${srcdir}/find_poppler_cmake.patch
  #patch -p1 -i ${srcdir}/find_azoth_multimediakit_cmake.patch
  #patch -p0 -i ${srcdir}/azoth_xoox_multimediakit.patch
  patch -p0 -i ${srcdir}/htthare_cmake.patch
  patch -p0 -i ${srcdir}/azoth_find_qca2.patch
  patch -p1 -i ${srcdir}/find_gstreamer_cmake.patch
  patch -p1 -i ${srcdir}/find_qwt_cmake_common.patch
  patch -p1 -i ${srcdir}/find_rbtorrent_cmake.patch
  patch -p1 -i ${srcdir}/find_lmp_libguess_cmake.patch
  patch -p1 -i ${srcdir}/find_lhtr_libtidy_cmake.patch
  patch -p1 -i ${srcdir}/find_qjson_cmake_common.patch

  cd ${srcdir}
  mv ${_realname} "${srcdir}/${CARCH}"
}

build() {
  #if [ "${CARCH}" != "x86_64" ]; then
  #  return
  #fi
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  #pushd ${MINGW_PREFIX} > /dev/null
  #export PREFIX_DEP=`pwd -W`
  #popd > /dev/null

  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DMINGW_PREFIX="${MINGW_PREFIX}" \
    -DWITH_PLUGINS=True \
    -DENABLE_SB2=True \
    -DENABLE_AZOTH=True \
    -DENABLE_CRYPT=True \
    -DENABLE_AZOTH_VADER=True \
    -DENABLE_MEDIACALLS=False \
    -DENABLE_AZOTH_AUTOPASTE=True \
    -DENABLE_AZOTH_ROSENTHAL=True \
    -DENABLE_AZOTH_WOODPECKER=True \
    -DENABLE_SECMAN=True \
    -DENABLE_AUSCRIE=True \
    -DENABLE_IMGASTE=True \
    -DENABLE_LACKMAN=True \
    -DENABLE_POSHUKU=True \
    -DENABLE_POSHUKU_CLEANWEB=True \
    -DENABLE_HISTORYHOLDER=True \
    -DENABLE_HTTP=True \
    -DENABLE_SYNCER=False \
    -DENABLE_TABSESSMANAGER=True \
    -DENABLE_CPULOAD=True \
    -DENABLE_DOLOZHEE=True \
    -DENABLE_HARBINGER=True \
    -DENABLE_NETSTOREMANAGER=True \
    -DENABLE_OORONEE=True \
    -DENABLE_TOUCHSTREAMS=True \
    -DENABLE_CEMENTO=True \
    -DENABLE_ROSENTHAL=True \
    -DENABLE_LASTFMSCROBBLE=True \
    -DENABLE_MONOCLE=True \
    -DENABLE_BLASQ=True \
    -DENABLE_LEMON=False \
    -DENABLE_VTYULC=False \
    -DENABLE_HTTHARE=True \
    -DGIT_CMD=`which git` \
    -DENABLE_POLEEMERY=True \
    -DENABLE_LHTR=True \
    -DENABLE_OTLOZHU=True \
    -DENABLE_OTLOZHU_SYNC=False \
    -DENABLE_LMP=True \
    -DUSE_GSTREAMER_10=True \
    -DENABLE_LMP_LIBGUESS=True \
    -DENABLE_LMP_BRAINSLUGZ=True \
    -DENABLE_LMP_DUMBSYNC=True \
    -DENABLE_LMP_GRAFFITI=True \
    -DENABLE_LMP_HTTSTREAM=True \
    -DENABLE_LMP_JOS=False \
    -DENABLE_LMP_MP3TUNES=True \
    -DENABLE_LMP_MTPSYNC=False \
    -DWITH_X11=False \
    -DENABLE_TORRENT=True \
    -DENABLE_AZOTH_OTROID=True \
    -DENABLE_SNAILS=False \
    -DENABLE_AZOTH_TRACOLOR=True \
    -DUSE_CPP14=True \
    ${srcdir}/${CARCH}/src/


  # -DQJSON_DIR="${PREFIX_DEP}/" \
  # -DQTMULTIMEDIAKIT_PREFIX="${PREFIX_DEP}/" \
  # -DLIBTIDY_DIR="${PREFIX_DEP}/" \
  # -DLibGuess_DIR="${PREFIX_DEP}/" \
  # -DRBTorrent_DIR="${PREFIX_DEP}/" \
  # -DRBTorrent_LIBRARY="${PREFIX_DEP}/lib/libtorrent-rasterbar.dll.a" \
  # -DQWT_DIR="${PREFIX_DEP}/" \
  # -DQWT_INCLUDE_DIRS="${PREFIX_DEP}/include/qwt" \
  # -DQWT_LIBRARIES="${PREFIX_DEP}/lib/libqwt.a" \
  # -DPC_GSTREAMER_LIBRARY_DIRS="${PREFIX_DEP}/lib" \
  # -DGSTREAMER_INCLUDE_DIR="${PREFIX_DEP}/include/gstreamer-1.0" \
  # -DGSTREAMER_DIR="${PREFIX_DEP}/" \
  #  ENABLE_SYNCER - laretz
  #  ENABLE_LEMON - netlink (nl)

  make ${MAKEFLAGS} # VERBOSE=1
}

package() {
  #if [ "${CARCH}" != "x86_64" ]; then
  #  return
  #fi
  cd $srcdir/build-${MINGW_CHOST}
  make -j1 install
}
